/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.esakk001;
import java.awt.Component;
import java.awt.Graphics;
import java.io.IOException;
import javax.swing.Icon;
import org.netbeans.spi.actions.AbstractSavable;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.NotifyDescriptor.Confirmation;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
/**
 *
 * @author esakk001
 */
public class MySavable extends AbstractSavable implements Icon {    
        MySavable() {
            register();
        }
        @Override
        protected String findDisplayName() {

            return null; 
        }
        @Override
        protected void handleSave() throws IOException {
            Confirmation message = new NotifyDescriptor.Confirmation("Do you want to save \""
                   + "\"?",
                    NotifyDescriptor.OK_CANCEL_OPTION,
                    NotifyDescriptor.QUESTION_MESSAGE);
            Object result = DialogDisplayer.getDefault().notify(message);
            if (NotifyDescriptor.YES_OPTION.equals(result)) {
                // add jpa code for persisting our change
                EntityManager entityManager = Persistence.createEntityManagerFactory("QnrLibraryPU").createEntityManager();
                entityManager.getTransaction().begin();
               
               
                unregister();
                // refresh the viewer
              
            }
        }

        @Override
        public boolean equals(Object o) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public int hashCode() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

      

        @Override
        public int getIconWidth() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public int getIconHeight() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}